/*
#Copyright (c) 2013, Philippe Bordron <philippe.bordron@gmail.com>
#
# This file is part of SIPPER.
#
# DCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with SIPPER.  If not, see <http://www.gnu.org/licenses/>
*/
package combi.wip.graph.algo.ksp.threads;


public class ThreadPourControleChemins extends Thread{

	protected static int  nb_threads;
	private int nb_enCours = 0;
	private int cpt=0;	
	
	public ThreadPourControleChemins(int nb_threads)
	{
		ThreadPourControleChemins.nb_threads = nb_threads;
	}
	
	protected synchronized void add()
	{
		cpt++;
		nb_enCours++;
		//System.err.println("Creation " +nb_enCours);
		// quota atteint
		if (nb_enCours > nb_threads)
		{
			//System.err.println("Attente");
			try {

				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public synchronized void remove()
	{
		nb_enCours--;
		//System.err.println("Reprise "+ nb_enCours);
		notify();
	}
}
